import 'package:flutter/material.dart';

extension ColorHex on Color {
  /// 使用十六进制字符串来创建颜色，支持 RGB 和 RGBA 两种格式。
  ///
  /// RGB: #FA0011 or FA0011
  ///
  /// RGBA: #FA0011FF or FA0011FF
  static Color? from(String hexStr) {
    String value;
    if (hexStr.startsWith('#')) {
      value = hexStr.substring(1);
    } else {
      value = hexStr;
    }

    // 系统的创建方法是 ARGB
    // 因此需要将 RGBA 转换为 ARGB
    if (value.length == 6) {
      value = 'FF$value';
    } else if (value.length == 8) {
      final a = value.substring(6, 8);
      final rgb = value.substring(0, 6);
      value = '$a$rgb';
    }

    final intValue = int.tryParse(value, radix: 16);
    if (intValue == null) {
      return null;
    } else {
      return Color(intValue);
    }
  }
}

/// 基础颜色管理
class MagicColors {
  /// 头部——标题颜色 #FF333333
  static const topTitle = Color(0xFF333333);

  /// 主标题颜色 黑色
  static const title = Colors.black;

  /// 副标题或文本颜色 #FF686E73
  static const subtitle = Color(0xFF686E73);

  /// 不可用时副标题或文本颜色 #FFB8BFC5
  static const disabledSubtitle = Color(0xFFB8BFC5);

  /// 次要副标题颜色 #FF9BA3A9
  static const secondarySubtitle = Color(0xFF9BA3A9);

  /// 描述文本颜色 #FFB8BFC5
  static const describe = Color(0xFFB8BFC5);


  /// 灰色背景 #FFF8F9FA
  static const greyBackground = Color(0xFFF8F9FA);

  /// 用于 button 的水平渐变：浅蓝色 #FF56A9FC -> #FF4CD3FC
  static const themeGradient = LinearGradient(
    colors: [
      themeBackground,
      Color(0xFF102437),
    ],
  );

  /// 用于 button 的水平渐变：蓝色 #FF3CBDF9 -> #FF3E6CF0
  static const blueGradient = LinearGradient(
    colors: [
      Color(0xFF3CBDF9),
      itemCardTitle,
    ],
  );

  static const orangeGradient = LinearGradient(
    colors: [
      Color(0xFFFFEF83),
      Color(0xFFFFBD5B),
    ],
  );

  /// 我的幸运币 渐变背景
  static const coinBackgroundGradient = LinearGradient(
    colors: [
      Color(0xFFC8E3FD),
      Color(0xFFD7F9FC),
    ],
  );

  /// 描述下划线颜色 #FFF2F4F5
  static const divider = Color(0xFFF2F4F5);

  /// 边框颜色 #FFC9CFD4
  static const border = Color(0xFFC9CFD4);

  /// 不可用时边框颜色
  static const disabledBorder = Color(0xFFE8EAEB);

  /// 主题色，多用于背景 #FF56A9FC
  static const themeBackground = Color(0xFF102437);

  /// 浅主题背景色 #FFF8F2FF
  static const lightThemeBackground = Color(0xFFF2F9FF);

  /// 主题色阴影 #4256A9FC
  static const themeShadow = Color(0x4256A9FC);
  //蓝色、现在在登录页用到
  static const loginWelcome = Color(0XFF64ECFF);

  /// 主题色，多用于标题 #FF55AAFC
  static const themeTitle = Color(0xFF212A39);

  /// 主题色，用于半透明背景 #3A56A9FC
  static const themeTranBackground = Color(0x3A56A9FC);

  ///用于金币总额 #FF95B9ED
  static const coinsTitle = Color(0xFF95B9ED);

  ///用于金币总额 #FFF79039
  static const coinsPlus = Color(0xFFFF7F00);

  ///用于魔盒详情页盒子总额 #FFFF7F1B
  static const boxDetailsPriceColor = Color(0xFFFF7F1B);

  ///用于魔盒首页卷按钮 #FF7B8FE3
  static const boxCouPonColor = Color(0xFF7B8FE3);

  static const boxDetailsBtnBgColor = Color(0xFFAFE3E5);

  ///用于魔盒首页购买按钮提示 #FF005658
  static const boxActionTipsColor = Color(0xFF005658);

  ///用于魔盒首页商品价格颜色 #FFFF2C0F
  static const boxPriceRedTipsColor = Color(0xFFFF2C0F);

  ///用于魔盒首页盒子名称颜色 #FF3F719B
  static const boxNameColor = Color(0xFF3F719B);

  ///用于魔盒首页商品价格颜色 #FF486AA5
  static const boxDetailsColor = Color(0xFF486AA5);

  //查看全部
  static const boxDetailsCheckColor = Color(0xFF476BA4);

  ///用于魔盒详情页概率展示背景颜色 #FFF5F9FF
  static const boxDetailsChangeBgColor = Color(0xFFF5F9FF);

  ///用于魔盒详情页商品列表文案背景颜色 #FFE8F1FF
  static const boxDetailsGoodsListItemTextBgColor = Color(0xFFCFF7F8);

  ///用于魔盒详情页商品价格背景颜色 #FFE1EEFF
  static const boxDetailsGoodsPriceBgColor = Color(0xFFE1EEFF);

  ///用于魔盒详情页商品价格颜色 #FF668AC9
  static const boxDetailsGoodsPriceColor = Color(0xFF668AC9);

  ///用于魔盒详情页商品列表背景颜色 #FFEEEEEE
  static const boxGoodsListPopBgColor = Color(0xFFEEEEEE);

  ///用于魔盒购买弹窗副标题文字颜色 #FF041C92
  static const boxBuySubTitleColor = Color(0xFF041C92);

  ///用于魔盒购买弹窗促销提示边框颜色 #FFFF7854
  static const boxBuyItemDiscountBorderColor = Color(0xFFFF7854);

  ///用于魔盒购买弹窗促销提示背景颜色 #FFFFEE9F
  static const boxBuyItemDiscountBgColor = Color(0xFFFFEE9F);

  ///用于魔盒购买弹窗促销提示文字颜色 #FFD34500
  static const boxBuyItemDiscountTitleColor = Color(0xFFD34500);

  ///用于魔盒购买弹窗价格文字颜色 #FF1B2D85
  static const boxBuyItemPriceColor = Color(0xFF1B2D85);

  ///用于魔盒购买弹窗原价格文字颜色 #FF657996
  static const boxBuyItemOriginalPriceColor = Color(0xFF657996);

  ///用于魔盒购买弹窗标题文字颜色 #FFfae0a6
  static const boxBuyDialogTitleColor = Color(0xFFfae0a6);

  ///用于魔盒购买弹窗渐变颜色 #FFF0F3Fa
  static const boxBuyDialogBgGradLent = LinearGradient(
    colors: [
      Colors.transparent,
      Colors.white,
    ],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
    stops: [0, 0],
  );

  ///用于魔盒支付弹窗标签颜色 #FFFF1B1B
  static const boxPayTagColor = Color(0xFFFF1B1B);

  ///用于魔盒支付弹窗商品数量颜色 #FF888888
  static const boxPayGoodsNumColor = Color(0xFF888888);

  ///用于魔盒支付弹窗商品价格颜色 #FFE30B0B
  static const boxPayGoodsPriceColor = Color(0xFFE30B0B);

  ///用于魔盒支付弹窗支付按钮背景颜色 #FF3DE5C3
  static const boxPayBtnBgColor = Color(0xFF3DE5C3);

  ///用于魔盒打开弹窗文字渐变颜色 #FFDFEBFF
  static const boxOpenTitleColor = Color(0xFFDFEBFF);

  ///用于魔盒打开弹窗文字渐变颜色 #FFFFEE51
  static const boxOpenTitleNumColor = Color(0xFFFFEE51);

  ///用于魔盒打开弹窗文字渐变颜色 #FFFFB13E
  static const boxOpenTitleNumColor2 = Color(0xFFFFB13E);

  ///用于魔盒商品列表普通概率颜色 #FFA7A7A7
  static const boxGoodsListRoteNormalColor = Color(0xFFA7A7A7);

  ///用于魔盒商品列表选中概率颜色 #FFC88800
  static const boxGoodsListRoteSelectColor = Color(0xFFC88800);

  ///用于魔盒商品列表选中概率颜色 #FFB2B2B2
  static const boxGoodsListRoteNormalBorderColor = Color(0xFFB2B2B2);

  ///用于魔盒支付弹窗商品折扣颜色 #FFFF0000
  static const boxPayGoodsDiscountsTagColor = Color(0xFFFF0000);

  ///用于魔盒打开弹窗商品区间颜色 #FFFFEA01
  static const boxOpenHitPriceRangeColor = Color(0xFFFFEA01);

  ///用于魔盒打开弹窗文字阴影颜色 #FF2FC2FF
  static const boxOpenTitleShadowColor = Color(0xFF2FC2FF);

  ///用于弹窗背景颜色 #B2000000
  static const dialogBackgroundColor = Color(0xB2000000);

  /// 道具卡标题颜色 #FF3E6CF0
  static const itemCardTitle = Color(0xFF3E6CF0);

  ///用于待支付倒计时颜色 #FFFC2828
  static const orderDetailsCunDownTimeColor = Color(0xFFFC2828);

  ///用于首页开盒弹窗阴影颜色 #BF000000
  static const boxOpenDialogShadowColor = Color(0xBF000000);

  /// 优惠券按钮标题色
  static const couponButtonTitle = Color(0xFF9C4500);

  /// 没有优惠券提示颜色
  static const unCouponTips = Color(0xFF828282);

  /// 优惠券列表的背景色
  static const CouponListBg = Color(0xFFEEF1F4);

  /// 引导提示文案颜色 FF48D5B8
  static const showCaseTipsColor = Color(0xFF48D5B8);

  /// 引导提示线条和圆点颜色 FF48D5B8
  static const showCaseLineColor = Color(0x9948D5B8);

  /// 引导按钮背景颜色 FFE4FFF5
  static const showCaseBtnBgColor = Color(0xFFE4FFF5);

  ///大佬榜单渐变颜色#C5D5FD
  static const rankingStartColor = Color(0xFFC5D5FD);

  ///开盒榜单按钮背景颜色#FFE7EEFF
  static const rankingItemColor = Color(0xFFE7EEFF);

  ///用于大佬榜单渐变
  static const rankingListGradLent = LinearGradient(
    colors: [
      rankingStartColor,
      Colors.white,
    ],
    begin: Alignment.topCenter,
    end: Alignment.bottomCenter,
    stops: [0, 0.13],
  );

  ///大佬榜单图片描边背景颜色 #FFC5D5FD
  static const rankingItemGoodsImgBorderColor = Color(0xFFC5D5FD);

  ///大佬榜单图片描边背景颜色 #FF5282D2
  static const rankingItemGoodsNameTextColor = Color(0xFF5282D2);

  ///大佬帮当吸欧气渐变色左#FF3FB9F9
  static const rankingItemRespireLeftColor = Color(0xFF3FB9F9);

  ///大佬帮当吸欧气渐变色左#FF3E6CF0
  static const rankingItemRespireRightColor = Color(0xFF3E6CF0);

  ///用于大佬榜单吸欧气渐变
  static const rankingItemRespireGradLent = LinearGradient(
    colors: [
      rankingItemRespireLeftColor,
      rankingItemRespireRightColor,
    ],
    begin: Alignment.centerLeft,
    end: Alignment.centerRight,
  );

  ///全部筛选弹窗类别普通文案
  static const categoryNormalTitle = Color(0xFF979797);

  ///详情页赠品模块头部文案左#FF196A98
  static const boxDetailsIntroductionTitle = Color(0xFF196A98);

  ///详情页赠品模块底部背景色#FFE9F2FF
  static const boxDetailsIntroductionBottom = Color(0xFFE9F2FF);

  ///详情页赠品模块赠送tag背景色左#FFFFF5F5
  static const boxDetailsIntroductionGiveTag = Color(0xFFFFF5F5);

  ///赠品弹窗item文字#FF2A3A78
  static const giveDialogTitle = Color(0xFF2A3A78);

  ///赠品弹窗金币item文字#FF5976ED
  static const giveDialogGoinTitle = Color(0xFF5976ED);

  ///赠品弹窗金币item文字#FFA6A6A6
  static const giveDialogSecondTitle = Color(0xFFA6A6A6);

  /// 秒杀活动 红色 FF0135
  static const flashSaleRed = Color(0xFFFF0135);

  /// 秒杀活动 枚红色 FF506D
  static const flashSaleRoseRed = Color(0xFFFF506D);

  /// 红色 FE115B (用于赠品、提示信息等)
  static const tipsRed = Color(0xFFFE115B);

  /// 红色 FF6B99
  static const tipsBorderRed = Color(0xFFFF6B99);
}
